<?php

namespace App\Http\Resources;

use App\Traits\BaseResource;
use Illuminate\Http\Resources\Json\Resource;

class Note extends Resource {
	use BaseResource;

	private function toEdit($request) {
		return $this->filterFields([
			'id' => $this->id,
			'title' => $this->title,
			'briefly' => $this->briefly,
			'image' => $this->image,
			'percent' => $this->percent,
			'num' => $this->num,
			'type' => $this->type,
			'status' => $this->status,
		]);
	}

	private function toIndex($request) {
		return $this->filterFields([
			'id' => $this->id,
			'content' => $this->content,
			'user' => $this->whenLoaded('user', function () {
				return $this->user;
			}),
			'reply' => $this->whenLoaded('reply', function () {
				return $this->reply;
			}),
			'created_at' => $this->created_at,
		]);
	}

	private function toRecord($request) {
		return $this->filterFields([
			'id' => $this->id,
			'title' => $this->title,
			'percent' => $this->percent,
			'num' => $this->num,
			'briefly' => $this->briefly,
			'image' => $this->image,
			'records' => new RecordCollection($this->records),
		]);
	}

	private function toComplete($request) {
		return $this->filterFields([
			'id' => $this->id,
			'title' => $this->title,
			'percent' => $this->percent,
			'num' => $this->num,
			'briefly' => $this->briefly,
			'image' => $this->image,
			'records' => (new RecordCollection($this->records))->type('complete'),
		]);
	}

	private function toDefault($request) {
		return $this->filterFields([
			'id' => $this->id,
			'title' => $this->title,
			'percent' => $this->percent,
			'num' => $this->num,
			'status' => $this->status,
			'created_at' => $this->created_at,
			'updated_at' => $this->updated_at,
		]);
	}
}
